package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理项目Controller类
 */
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;


    // 1.1 分页条件查询
    @GetMapping
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "护理项目名称") String name,
            @ApiParam(value = "状态：0-禁用，1-启用") Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        // TODO: 编写代码
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.getByPage(name, pageNum, pageSize, status);

        return ResponseResult.success(pageResponse);
    }

    // 1.2 新增
    @PostMapping
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDto) {
        // TODO: 编写代码
        nursingProjectService.add(nursingProjectDto);
        return ResponseResult.success();
    }


    // 1.3 根据id查询护理
    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> getById(@PathVariable Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return ResponseResult.success(nursingProjectVo);
    }

    // 1.4 修改
    @PutMapping
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.update(nursingProjectDto);
        return ResponseResult.success();
    }

    // 1.5 启用/禁用
    @PutMapping("/{id}/status/{status}")
    public ResponseResult status(@PathVariable Long id, @PathVariable Integer status) {
        nursingProjectService.status(id, status);
        return ResponseResult.success();
    }

    // 1.6 删除
    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Long id) {
        nursingProjectService.delete(id);
        return ResponseResult.success();
    }

    // 1.7 查询所有护理项目
    @GetMapping("/all")
    public ResponseResult<NursingProjectVo> getAll() {
        List<NursingProjectVo> nursingProjectVo = nursingProjectService.getAll();
        return ResponseResult.success(nursingProjectVo);
    }
}